# coding=utf-8
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from appium import webdriver


class Base():
    # capabilities = {'platformName': 'Android',
    #                 'platformVersion': '4.4.2',
    #                 'deviceName': '127.0.0.1:62001',
    #                 'appPackage': 'com.guokr.mentor',
    #                 'appActivity': '.ui.activity.MainActivity',
    #                 'unicodeKeyboard': True,
    #                 'resetKeyboard': True,
    #                 'noReset': True}
    #
    # def __init__(self):
    #     self.driver = webdriver.Remote('http://localhost:4723/wd/hub', self.capabilities)

    def __init__(self,driver):
        self.driver = driver

    def find_element(self, loc):
        """
        定位一个元素
        :param loc:元组类型，如loc=(id,'name')或者(BY.ID,'name')
        :return:返回一个元素
        """
        try:
            element = WebDriverWait(self.driver, 10).until(EC.presence_of_element_located(loc))
            return element
        except:
            print("%s找不到元素%s" % (self, loc))

    def find_elements(self, loc):
        """
        定位一组元素
        :param loc: 元组类型，如loc=(id,'name')或者(BY.ID,'name')
        :return: 返回一组元素
        """
        try:
            elements = WebDriverWait(self.driver, 10).until(EC.presence_of_all_elements_located(loc))
            return elements
        except:
            print("%s找不到一组元素%s" % (self, loc))